package com.css.zfzx.sjcj.modules.fourthgenerations.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.zfzx.sjcj.modules.fourthgenerations.repository.entity.QhGeoFourthgenerationsEntity;
import com.css.zfzx.sjcj.modules.fourthgenerations.service.QhGeoFourthgenerationsService;
import com.css.zfzx.sjcj.modules.fourthgenerations.viewobjects.QhGeoFourthgenerationsQueryParams;
import com.css.bpm.platform.utils.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author tao
 * @date 2020-11-27
 */
@Slf4j
@RestController
@RequestMapping("/qh/qhGeoFourthgenerationss")
public class QhGeoFourthgenerationsController {
    @Autowired
    private QhGeoFourthgenerationsService qhGeoFourthgenerationsService;

    @GetMapping("/queryQhGeoFourthgenerationss")
    public RestResponse queryQhGeoFourthgenerationss(HttpServletRequest request, QhGeoFourthgenerationsQueryParams queryParams) {
        RestResponse response = null;
        try{
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            JSONObject jsonObject = qhGeoFourthgenerationsService.queryQhGeoFourthgenerationss(queryParams,curPage,pageSize);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @PostMapping("/queryQhGeoFourthgenerationssNoPage")
    public RestResponse queryQhGeoFourthgenerationss(@RequestBody QhGeoFourthgenerationsQueryParams queryParams) {
        RestResponse response = null;
        try{
            JSONObject jsonObject = qhGeoFourthgenerationsService.queryQhGeoFourthgenerationss(queryParams);
            response = RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    @GetMapping("{id}")
    public RestResponse getQhGeoFourthgenerations(@PathVariable String id) {
        RestResponse response = null;
        try{
            QhGeoFourthgenerationsEntity qhGeoFourthgenerations = qhGeoFourthgenerationsService.getQhGeoFourthgenerations(id);
            response = RestResponse.succeed(qhGeoFourthgenerations);
        }catch (Exception e){
            String errorMessage = "获取失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @PostMapping
    public RestResponse saveQhGeoFourthgenerations(@RequestBody QhGeoFourthgenerationsEntity qhGeoFourthgenerations) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhGeoFourthgenerationsService.saveQhGeoFourthgenerations(qhGeoFourthgenerations);
            json.put("message", "新增成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "新增失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;

    }
    @PutMapping
    public RestResponse updateQhGeoFourthgenerations(@RequestBody QhGeoFourthgenerationsEntity qhGeoFourthgenerations)  {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhGeoFourthgenerationsService.updateQhGeoFourthgenerations(qhGeoFourthgenerations);
            json.put("message", "修改成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "修改失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    @DeleteMapping
    public RestResponse deleteQhGeoFourthgenerationss(@RequestParam List<String> ids) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try{
            qhGeoFourthgenerationsService.deleteQhGeoFourthgenerationss(ids);
            json.put("message", "删除成功!");
            response = RestResponse.succeed(json);
        }catch (Exception e){
            String errorMessage = "删除失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }


}